package concurrent1;

import java.util.concurrent.*;

public class ThreadPoolExecutor1 {
    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,
                10,
                10L,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(100),
                new ThreadFactory() {
                    @Override
                    public Thread newThread(Runnable r) {
                        return new Thread(r,"CustomThread-" + Thread.currentThread().getId());
                    }
                },
                new ThreadPoolExecutor.CallerRunsPolicy());

        executor.execute(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("111111");
            System.out.println(Thread.currentThread().getName());
        });
        executor.execute(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("111111");
            System.out.println(Thread.currentThread().getName());
        });


    }
}
